<!--- Return the Exchange Login Info as Struct (could do this in your application.cfc) --->
<cffunction name="SCF_Exchange_GetCredentials" returntype="struct" output="no">
	<cfset var retval = StructNew() />

	<cfset retval.Exchange_Login = "Besadmin" />
	<cfset retval.Exchange_Pwd = "*25or6to4*" />
	
	<cfreturn retval />
</cffunction>

<!---
	Returns the size of the specified user's mailbox in megabytes. 
	Returns less than 0 on failure (-1 for general error, -2 for size overflows)
--->
<cffunction name="SCF_Exchange_GetMailboxSize" returntype="numeric" output="no">
	<cfargument name="username" type="string" required="no" default="#ListGetAt(CGI.AUTH_USER, 2, '\')#" />
	
	<!--- Necessary as threads do not inherit parent scope --->
	<cfset VARIABLES.username = username />
	<cfset VARIABLES.ExchangeCredentials = SCF_Exchange_GetCredentials() />
	
	<!---
		Connect to the exchange server inside a thread. This is necessary
		as sometimes the exchange connection can hang
	--->
	<cfthread name="MailboxSizeCheckThread" priority="low" action="run">
		<cfset THREAD.mailboxsize = -1 />

		<cfset size = 0 />
		
		<cfexchangeconnection action="open" connection="conn"
			server="10.100.1.181" protocol="https" mailboxname="#username#" 
			username="#ExchangeCredentials.Exchange_Login#"
			password="#ExchangeCredentials.Exchange_Pwd#" />

		<cfexchangeconnection connection="conn" name="exchRoot" 
			action="getsubfolders" recurse="true" folder="/" />

		<cfloop query="exchRoot">
			<!---
				If the user has a folder so big it breaks the integer for
				sizing, return -2
			--->
			<cfif FolderSize lt 0>
				<cfset size = 0 />
				<cfset THREAD.mailboxsize = -2 />
				<cfbreak />
			</cfif>
			
			<cfset size += FolderSize />
		</cfloop>

		<cfif size GT 0>
			<cfset THREAD.mailboxsize = Round(size / 1048576) />
		</cfif>
	</cfthread>

	<!--- Join running thread, but only wait for 30 seconds --->
	<cfthread name="MailboxSizeCheckThread" timeout="30000" action="join" />

	<!--- Kill thread if it's still running --->
	<cfthread name="MailboxSizeCheckThread" action="terminate" />

	<cfreturn MailboxSizeCheckThread.mailboxsize />
</cffunction>

<cfoutput>#SCF_Exchange_GetMailboxSize("cramey")#</cfoutput>